<template>
	<div>
		<el-button type="text" @click="dialogFormVisible = true">添加管理员</el-button>
		<el-table :data="tableData" style="width: 100%">

			<el-table-column label="ID" width="180">
				<template slot-scope="scope">
					<span style="margin-left: 10px">{{ scope.row.id }}</span>
				</template>
			</el-table-column>
			<el-table-column label="姓名" width="180">
				<template slot-scope="scope">
					<span>{{ scope.row.name }}</span>
				</template>
			</el-table-column>
			<el-table-column label="日期" width="180">
				<template slot-scope="scope">
					<i class="el-icon-time"></i>
					<span style="margin-left: 10px">{{ scope.row.date }}</span>
				</template>
			</el-table-column>

			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>


		<el-dialog :modal="false" title="添加管理员" :visible.sync="dialogFormVisible">
			<el-form :model="form">
				<el-form-item label="名称" :label-width="formLabelWidth">
					<el-input v-model="form.name" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="权限" :label-width="formLabelWidth">
					<el-select v-model="form.region" placeholder="请选择权限">
						<el-option label="超级管理员" value="1"></el-option>
						<el-option label="运营" value="2"></el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="addAdmin">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dialogTableVisible: false,
				dialogFormVisible: false,
				form: {
					name: '',
					region: '',
				},
				formLabelWidth: '120px',
				tableData: [{
					id: 1,
					date: '2016-05-02',
					name: '王小虎',
					region:'1'
				}]
			}
		},
		methods: {
			handleEdit(index, row) {
				this.dialogFormVisible=true;
				this.form.name=row.name;
				this.form.region=row.region
			},
			handleDelete(index, row) {
				this.tableData.splice(index,1);
				console.log(index, row);
			},
			addAdmin() {
				this.tableData.push({
					id: this.tableData.length++,
					name: this.form.name,
					date: "2016-05-02",
					region:this.form.region
				});
				this.dialogFormVisible=false;

			}

		}
	}
</script>
